package com.leet.competition;

import java.util.Arrays;
import java.util.Collections;

public class ReversePrefix {
    public String reversePrefix(String word, char ch) {
        int i = word.indexOf(ch);
        char[] chars = word.toCharArray();
        int k =0;
        String res = word;
        if(i!=-1){
            StringBuilder ans = new StringBuilder();
            String r  = word.substring(i+1);
            for(int j = i;j > 0;j-- ){
                ans.append(chars[j]);
            }

            ans = ans.reverse();
            res = String.valueOf(ans) + r;
        }
        return res;
    }
}
